package com.acme;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;
	
	public CheckingAccount(double amount, double overdraft) {
		super(amount);
		this.overdraft = ((overdraft > 0) ? overdraft : 0);
	}
	
	@Override
	public void withdraw(double amount) {
		if(amount >= 0) {
			if(this.balance >= amount) {
				this.balance -= amount;
			} else if(this.balance + this.overdraft >= amount) {
				this.overdraft -= amount-this.balance;
				this.balance = 0;
			} else {
				this.balance = -1;
				this.overdraft = 0;
				System.out.println("You have no money to withdraw!");
			}
		} else {
			this.balance = -1;
			this.overdraft = 0;
			System.out.println("You can't withdraw negative amount!");
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return this.balance + this.overdraft;
	}

}
